package com.search.server.impl;

import com.search.server.SearchServiceGrpc;
import com.search.server.SearchServiceProto;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

import java.util.List;

public class SearchClient {
    public static void main(String[] args) {
            SearchServiceGrpc.SearchServiceBlockingStub stub=null;
            ManagedChannel channel=null;
        channel = ManagedChannelBuilder
                .forAddress("127.0.0.1", 9999)
                .usePlaintext() //使用纯文本类型
                .build();
        stub = SearchServiceGrpc.newBlockingStub(channel);

        String query = "1,2,3,4";
        String[] split = query.split(",");
        SearchServiceProto.SearchResponse response = stub.search(SearchServiceProto.SearchRequest.newBuilder()
                .setCorpusValue(Integer.parseInt(split[0]))
                .setPageNumber(Integer.parseInt(split[1]))
                .setQuery(split[2])
                .setResultPerPage(Integer.parseInt(split[3]))
                .build());
        int code = response.getCode();
        String msg = response.getMsg();
        List<SearchServiceProto.Data> dataList = response.getDataList();
        System.out.println(code);
        System.out.println(msg);

    }
}
